import UIKit

class MainTabBar: UITabBar {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let w = bounds.size.width/5
        let h = bounds.size.height
        let rect = CGRectMake(0, 0, w, h)
        var index : CGFloat = 0
        for subview in subviews {
            if (subview.isKindOfClass(NSClassFromString("UITabBarButton")!)) {
                subview.frame = CGRectOffset(rect, index*w, 0)
                index += (index == 1 ? 2 : 1)
                
            }
            
        }
        plusbtn.frame = CGRectOffset(rect, 2*w, 0)
    }
    //MARK:懒加载加号按钮
    lazy var plusbtn:UIButton = {
       let btn = UIButton()
        //设置背景图片
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        //设置图片
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        
        //添加
        self.addSubview(btn)
        
        return btn
    }()
}
